"""
plot_relative2random.py
Jose Guzman, sjm.guzman@gmail.com
Date: Fri Mar  7 23:00:10 CET 2014

Plots the counts relative to random
"""
import numpy as np
from matplotlib.pyplot import figure, show

# import random values
nonconnected_rnd = np.load("unconnected.npy")
unidirectional_rnd = np.load("unidirectional.npy")
bidirectional_rnd = np.load("bidirectional.npy")


# empirical values
N = 10970/2 # number of pair recordings
p = 111/10970. # averagej

# theoretical values
nonconnected_th = N*(1-p)*(1-p)
unidirectional_th = N*2*(1-p)*p
bidirectional_th = N*p*p

# transform empirical data in counts relative to random
nonconnected = ((10970-111) - nonconnected_rnd)/nonconnected_th
unidirectional = (103 - unidirectional_rnd)/unidirectional_th
bidirectional = (4 - bidirectional_rnd)/bidirectional_th

# FIGURE: bar chart
labels = ['non-connected','unidirectional','bidirectional']
data = [np.mean(x) for x in (nonconnected, unidirectional, bidirectional)]
std = [np.std(x) for x in (nonconnected, unidirectional, bidirectional)]
xlocations = [.5, 1.0, 1.5] 

fig = figure(1)
ax = fig.add_subplot(111)
ax.bar(xlocations, data, yerr=std, ecolor='k', facecolor='black', width = 0.4)
ax.set_xlim(xmin = 0.4, xmax =2)
ax.set_ylim(ymin = -0.5, ymax =10)
ax.set_ylabel('Counts above random')

# ticks
ax.get_xaxis().tick_bottom()
ax.get_yaxis().tick_left()
show()
